<script type="text/javascript">
    $(document).ready(function(){
        $.ajax({
            url: '{{$jqgrid.url_metadata}}',
            type: 'GET',
            dataType: 'json',
            error: function(){
                alert('Can not load init jqrip!');
            },
            success: function(data){
                $("#{{$jqgrid.id}}").jqGrid({ 
                    url: '{{$jqgrid.url_data}}',
                    datatype: "json",
                    mtype: "POST",
                    colNames: data.names,
                    colModel: data.model,
                    height:'auto',
                    autowidth: true,
                    rowNum:10,
                    rowList:[10,20,30],
                    pager: '#{{$jqgrid.pager}}',
                    caption: "{{$jqgrid.caption}}",
                    viewrecords: true,
                    multiselect: false,
                    sortable: true
                });
                jQuery("#{{$jqgrid.id}}").jqGrid(
                    'navGrid',
                    '#{{$jqgrid.pager}}', 
                    {view:true, add:false, edit:false, del:false, search:true, refresh: true}, //options
                    {}, // edit options 
                    {}, // add options 
                    {}, // del options 
                    {height:'auto',closeAfterSearch:true,multipleSearch:true} // search options 
                ).navButtonAdd('#{{$jqgrid.pager}}',{
                    caption:"{{$language->line('edit')}}", 
                    buttonicon:"ui-icon-edit", 
                    onClickButton: function(){ 
                        var gr = $("#{{$jqgrid.id}}").jqGrid('getGridParam', 'selrow');
                        if( gr != null ) urlGo('{{$jqgrid.url_edit}}/id/'+gr);
                        else alert("{{$language->line('please_select')}}");
                    }, 
                    position:"last"
                });
                jQuery("#{{$jqgrid.id}}").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
            }
        });
    });
</script>